package com.ihunanren.biz.taobao.ao.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.ihunanren.biz.result.Result;
import com.ihunanren.biz.result.ResultSupport;
import com.ihunanren.biz.taobao.ao.ICouponsAo;
import com.ihunanren.common.CollectionUtils;
import com.ihunanren.common.spider.WebSpider;
import com.ihunanren.dao.pojo.TaobaoCouponsDO;
import com.ihunanren.dao.taobao.ITaobaoCouponsDao;

/**
 * @author kalman03
 */
public class CouponsAo implements ICouponsAo {

	private final static Logger log = LoggerFactory.getLogger(CouponsAo.class);
	@Autowired
	private ITaobaoCouponsDao couponsDao;
	@Autowired
	private WebSpider spider;
	
	@Override
	public Result getCouponUrls(int count) {
		Result result = new ResultSupport(false);
		if(count <= 0)return result;
		try {
			List<TaobaoCouponsDO> list = couponsDao.getCoupons(count);
			if(CollectionUtils.isNotEmpty(list)){
				result.setSuccess(true);
				result.setDefaultModel(list);
			}
		} catch (Exception e) {
			log.error("GetCoupons catch a exception----->",e);
		}
		return result;
	}

	@Override
	public void searchCouponsByLink(String httpLink) {
		try {
			spider.setBaseLink(httpLink);
			spider.doSpider();
		} catch (Exception e) {
			log.error("SearchCouponsByLink catch a exception----->",e);
		}
	}

	@Override
	public boolean isObtainOutOfTimes(String ip) {
		//log.error("ip is :"+ip);
		
		return false;
	}
}
